#ifndef WY_MSG_H
#define WY_MSG_H

#include <stdint.h>

/*
	messages for host's operations.
	from Agent, send to Moniter Server.
*/
enum host_opt {
	OPT_POWER=1,		//Power on the system, and store the hostname in msg_host_opt_st.data.
	OPT_SHUTDOWN,		//Shutdown the system.
	OPT_LOGOUT,		//Logout the system.
	OPT_RUN,		//Run a program, and store the program's infomation in msg_host_opt_st.data.
	OPT_SURF,		//Surfing the internet, and store the web address in msg_host_opt_st.data.
	OPT_OPEN,		//The program is open.
	OPT_CLOSE		//The program is close.
};

enum host_opt_level {
	OPT_LV_OK=1,
	OPT_LV_WARN,
	OPT_LV_ERROR
};

struct msg_host_opt_st {	//The operation of a host.
	uint32_t time;
	uint8_t opt[2];		//Must be one of the enum host_opt.
	uint8_t host_map;	//Host NO. saved in bitmap.
	uint32_t offset;	//The offset of data.
	uint8_t data[1];	//Store more information of opt.
} __attribute__((packed));


/*
	messages from Agent/Client/Moniter Server, make sure Agent/Client and Moniter Server is connected.
*/
/*
	Agent/Client端固定时间周期向Server端发数字，Server端收到数字后+1，并将+1后的数字返回给Agent/Client端，Agent/Client端根据数字的大小来确定网络链路是否正常。
	当网络链路不正常时，Agent端采取一定的手段限制主机的操作，Server端记录主机的异常状态，并向Client端发送。
*/
/*
	可以用Ping的方法实现该功能？？
*/
enum snd_type {
	S_SERVER=1,
	S_CLIENT,
	S_AGENT
};

struct msg_conn_st {
	uint8_t snd_type;	//发送方类别
	uint8_t snd_map;	//Sender NO. saved in bitmap.
	uint32_t num;
} __attribute__((packed));


/*
	Communication/system  messages.
*/
/*
	交互模块的通信协议。
	当msg_level为LV_CMT时，为普通交互协议，用于Agent/Client用户与Moniter Server之间段通信；当msg_level为LV_SYS时为系统通信协议，用于Agent/Client与
	Moniter Server模块之间发送系统信息的协议。
	msg_no是为了避免发送多条信息时，由于延时造成各组信息之间的错乱。
	Recevicer用位图保存，在Server端存有备份，当有Agent/Client链接上Server时，向Agent/Client发送一份被管主机位图。当位图有变化时进行同步。
	data_num用于保存将Messages分成里多少个blocks，接收端根据data_num和data_no来确认消息接收完全。
*/
/*
enum msg_level {
	LV_SYS=1,	//system msg
	LV_CMT		//communication msg
};
//Messages from Agent/Client to Moniter Server.
struct msg_cmt_2S_st {
	uint32_t time;
	uint8_t msg_level;	//message level:system msg,communication msg.
	uint8_t msg_no;		//The NO. of messages.防止发送多组信息时混乱。
	uint8_t rcv_num;	//The number of receivers.
	uint8_t data_num;	//The number of data blocks.
	uint8_t rcv_map;	//Receiver NO. saved in bitmap.
} __attribute__((packed));

//Messages from Moniter Server to Agent/Client.
struct msg_cmt_2AC_st {
	uint32_t time;
	uint8_t msg_level;
	uint8_t msg_no;
	uint8_t snd_map;	//Sender NO. saved in bitmap.
	uint8_t data_num;
} __attribute__((packed));

//The data of messages.
struct msg_cmt_data_st {
	uint8_t msg_no;		//The NO. of messages.
	uint8_t data_no;	//The NO. of data blocks.
	uint32_t offset;	//The offset of data.
	uint8_t data[1];	//Messages data.
} __attribute__((packed));
*/
enum msg_level {
	LV_SYS=1,	//system msg
	LV_CMT		//communication msg
};

struct msg_cmt_st {
	uint32_t time;
	uint8_t msg_level;      //message level:system msg,communication msg.
	uint8_t host_map;       //Receiver NO. saved in bitmap.
	uint32_t offset;        //The offset of data.
	uint8_t data[1];        //Messages data.
} __attribute__((packed));

/*
	Messages for host status change,from Server to Client.
*/
/*
	Server端从接收到的主机日志中分析出主机的当前状态，当主机状态改变时，向Client端发送msg_host_sts_st信息。
	Client根据主机的当前状态来显示主机信息，并通知管理员。
*/
//The status of a host
enum host_status {
	HS_LOGON=1,	//主机上线
	HS_LOGOUT,	//主机下线
	HS_OK,		//正常状态
	HS_WARNING,	//警告告警状态
	HS_CRITICLE	//严重告警状态
};

struct msg_host_status_st {
	uint32_t time;
	uint8_t host_map;	//Host NO. saved in bitmap.
	uint8_t status;		//The status of a host.
} __attribute__((packed));
#endif
